define(['jquery', 'city'], function(require, exports, module) {
    require.async('breed', function(a) {
        a.muInit($('#js-input-breed'));
    });
    var defaultCode = $('#js-search-form').find('input[name="city"]').val();
    if (defaultCode) {
        defaultCode = parseInt(defaultCode);
    } else {
        defaultCode = 0;
    }
    $('#js-city').city({
        defaultCode: defaultCode,
        code: $('input[name="city"]').val(),
        callback: function (code, name) {
            $('input[name="city"]').val(code);
        }
    });
    $('#js-search-form').on('submit', function () {
        var obj = $(this);
        var city = obj.find('input[name="city"]').val();

        var page = obj.find('input[name="page"]').val();
        var breed = obj.find('input[name="breed"]').val();
        breed = breed ? $.trim(breed) : '';
        breed = breed.replace(/[,，]$/, '');
        var sex = obj.find('input[name="sex"]:checked').val();
        var url = '/search_' + city + '_' + encodeURIComponent(breed) + '_' + sex + '_' + page;
        url += '.html';
        window.location.href = url;
        return false;
    });
});